package com.service.business.member.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.service.dao.mapper.MemberOutMapper;
import com.service.dao.model.MemberOut;
import com.service.business.member.service.MemberOutService;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;


/**
 * @author lisi
 */
@Service("memberOutService")
public class MemberOutServiceImpl extends ServiceImpl<MemberOutMapper, MemberOut> implements MemberOutService {


    @Override
    public MemberOut getLastMemberOutRecord(Integer memberId) {
        List<MemberOut> list = list(new QueryWrapper<MemberOut>().lambda()
                .eq(MemberOut::getMemberId, memberId)
                .orderByDesc(MemberOut::getCreateTime).last("limit 1"));
        return ObjectUtils.isEmpty(list) ? null : list.get(0);
    }

    @Override
    public MemberOut getSumMemberOutRecord(Integer memberId) {
        return baseMapper.sumMemberOut(memberId);
    }


}
